1. Aditya Kabir
  2. PowerBuilder
  3. Thursday, 3 April 2025 02:02 AM UTC

Hi this function was created before Powerbuilder supports Jsons and http requests, it's about calling a http webservice and return values. I have tried debugged it, what I found that it worked fine until that function was compeleted within VC++. here's my code on PB 

I have declared it on external function section

 function long    querytraccodg( & 
	general_struct  gs,& 
	  querytrackcode   qd, & 
	 ref long recordscount,& 
	 ref querytrackcoderet  tcr[],& 
	    ref general_ret_struct  grs) & 
LIBRARY "dgnewsbsapi.dll"  Alias for 'querytraccodg;Ansi' 

 

long ll_net,li_daysDifference

date ld_rq,ld_js
datetime ldt_ksrq, ldt_jsrq, ldt_syyjrq

ld_rq    = date(em_5.text)
ldt_ksrq = datetime(ld_rq)         
ld_js    = date(em_6.text)
ldt_jsrq = datetime(ld_js,time('23:59:59')) 


li_daysDifference = DaysAfter(date(ldt_jsrq), date(ldt_ksrq))

if li_daysDifference>31 then
	uf_ok(" Don't query date duration is over 31 days, programe may crashed due to too much datas")
	return
end if

ll_net=messagebox("query","are you sure need to query?",question!,yesno!)
if ll_net=2 then return 

querytrackcode qd
querytrackcoderet qtcrt[]


qd.fixmedins_code=gs_fixmedins_code

qd.medins_list_codg=trim(sle_medins_list_codg.text)
if isnull(qd.medins_list_codg) then qd.medins_list_codg="" 

qd.fixmedins_bchno=trim(sle_fixmedins_bchno.text)
if isnull(qd.fixmedins_bchno) then qd.fixmedins_bchno=""

qd.begndate=em_5.text
qd.enddate=em_6.text

qd.med_list_codg=trim(sle_med_list_codg.text)
if isnull(qd.med_list_codg) then qd.med_list_codg=""

qd.mdtrt_id=trim(sle_mdtrt_id.text)
if isnull(qd.mdtrt_id) then qd.mdtrt_id=""

qd.psn_no=""
qd.psn_cert_type=""

qd.certno=trim(sle_certno.text)
if isnull(qd.certno) then qd.certno=""

qd.psn_name=""
qd.drug_trac_codg=""

long ll_row,ll_result,ll_recordscount

for ll_row=1 to 5000
qtcrt[ll_row].fixmedinsCode=space(50)
qtcrt[ll_row].medListCodg=space(26)
qtcrt[ll_row].medinsListCodg=space(60)
qtcrt[ll_row].medinsListName=space(200)
qtcrt[ll_row].fixmedinsBchno=space(150)
qtcrt[ll_row].mdtrtId=space(60)
qtcrt[ll_row].mdtrtSetlType=space(60)
qtcrt[ll_row].bkkpSn=space(150)
qtcrt[ll_row].drugTracCodg=space(60)
qtcrt[ll_row].psnNo=space(60)
qtcrt[ll_row].psnCertType=space(60)
qtcrt[ll_row].certno=space(60)
qtcrt[ll_row].psnName=space(90)
qtcrt[ll_row].memo=space(500)
qtcrt[ll_row].trdnFlag=space(50)
qtcrt[ll_row].updtTime=space(50)
qtcrt[ll_row].opterName=space(100)
qtcrt[ll_row].rid=space(60)
qtcrt[ll_row].crteTime=space(50)
qtcrt[ll_row].optTime=space(50)
qtcrt[ll_row].opterId=space(50)
qtcrt[ll_row].crterName=space(100)
qtcrt[ll_row].crterId=space(50)
qtcrt[ll_row].optinsNo=space(50)
next

general_struct gs1

gs1.accesskey=gs_accesskey
gs1.secrekey=gs_secrekey
gs1.sbid=gs_fixmedins_code
gs1.insuplc_admdvs=gs_insuplc_admdvs
gs1.mdtrtarea_admvs=gs_mdtrtarea_admvs
gs1.opter_type="1"
gs1.opter=cur_no
gs1.opter_name=cur_Name
if isnull(gs1.opter_name) then gs1.opter_name=""

gs1.inf_time= String(datetime(today(),now()),"yyyy-mm-dd hh:mm:ss")

gs1.fixmedins_code=gs_fixmedins_code
gs1.fixmedins_name=gs_fixmedins_name
gs1.sign_no=gs_newsb_signo
gs1.returncode=0
gs1.iftest=gb_iftest

general_ret_struct grs1;
ll_recordscount=0

ll_result= querytraccodg( &
	  gs1, &
	  qd ,&
	 ll_recordscount,&
	 qtcrt,&
	 grs1)
	 
	 
if ll_result=0 then
	for ll_row=1 to  ll_recordscount
	   dw_3.insertrow(0)
	    dw_3.setitem(dw_3.rowcount(),"fixmedinsCode",qtcrt[ll_row].fixmedinsCode)
	    dw_3.setitem(dw_3.rowcount(),"medListCodg",qtcrt[ll_row].medListCodg)
	    dw_3.setitem(dw_3.rowcount(),"medinsListCodg",qtcrt[ll_row].medinsListCodg)
	    dw_3.setitem(dw_3.rowcount(),"medinsListName",qtcrt[ll_row].medinsListName)
	    dw_3.setitem(dw_3.rowcount(),"fixmedinsBchno",qtcrt[ll_row].fixmedinsBchno)
	    dw_3.setitem(dw_3.rowcount(),"mdtrtId",qtcrt[ll_row].mdtrtId)
	    dw_3.setitem(dw_3.rowcount(),"mdtrtSetlType",qtcrt[ll_row].mdtrtSetlType)
	    dw_3.setitem(dw_3.rowcount(),"bkkpSn",qtcrt[ll_row].bkkpSn)
	    dw_3.setitem(dw_3.rowcount(),"drugTracCodg",qtcrt[ll_row].drugTracCodg)
	    dw_3.setitem(dw_3.rowcount(),"psnNo",qtcrt[ll_row].psnNo)
	    dw_3.setitem(dw_3.rowcount(),"psnCertType",qtcrt[ll_row].psnCertType)
	    dw_3.setitem(dw_3.rowcount(),"certno",qtcrt[ll_row].certno)
	    dw_3.setitem(dw_3.rowcount(),"psnName",qtcrt[ll_row].psnName)
	    dw_3.setitem(dw_3.rowcount(),"memo",qtcrt[ll_row].memo)
	    dw_3.setitem(dw_3.rowcount(),"trdnFlag",qtcrt[ll_row].trdnFlag)
	    dw_3.setitem(dw_3.rowcount(),"updtTime",qtcrt[ll_row].updtTime)
	    dw_3.setitem(dw_3.rowcount(),"opterName",qtcrt[ll_row].opterName)
	    dw_3.setitem(dw_3.rowcount(),"rid",qtcrt[ll_row].rid)
	    dw_3.setitem(dw_3.rowcount(),"crteTime",qtcrt[ll_row].crteTime)
	    dw_3.setitem(dw_3.rowcount(),"optTime",qtcrt[ll_row].optTime)
	    dw_3.setitem(dw_3.rowcount(),"opterId",qtcrt[ll_row].opterId)
	    dw_3.setitem(dw_3.rowcount(),"crterName",qtcrt[ll_row].crterName)
	    dw_3.setitem(dw_3.rowcount(),"crterId",qtcrt[ll_row].crterId)
	    dw_3.setitem(dw_3.rowcount(),"optinsNo",qtcrt[ll_row].optinsNo)
    next
	 
	 if ll_recordscount=9 then
		uf_ok("sorry no results found")
	end if
	 
else
	uf_ok("Error occured:"+ grs1.err_msg)
 
	
end if

 

here is code on VC++ side:

int  _stdcall  querytraccodg(
	 general_struct & gs,
	 querytrackcode & qd,
	 int & recordscount,
	 querytrackcoderet * tcr,
	 general_ret_struct & grs)
 {
	 setlocale(LC_ALL, "");
	 string infno, msgid;
	 infno = "3513";
	 msgid = gs.sbid;

	 std::time_t rawtime;
	 std::tm timeinfo;
	 char buffer[80];

	 std::time(&rawtime);
	 localtime_s(&timeinfo, &rawtime);

	 std::strftime(buffer, 80, "%Y%m%d%H%M%S", &timeinfo);
	 string datetimestr = buffer;
	 msgid = msgid + datetimestr;

	 int mynum = rand() % 10000;
	 string mynumorgstr = to_string(mynum);
	 string mynumstr = std::string(4 - mynumorgstr.length(), '0') + mynumorgstr;

	 msgid = msgid + mynumstr;

	 json::value obj, dataitem,  inputitem;

	 
	 wstring fields = L"fixmedins_code";
	 assigncstring2json(dataitem, fields, qd.fixmedins_code);

	 fields = L"medins_list_codg";
	 assigncstring2json(dataitem, fields, qd.medins_list_codg);

	 fields = L"fixmedins_bchno";
	 assigncstring2json(dataitem, fields, qd.fixmedins_bchno);

	 fields = L"begndate";
	 assigncstring2json(dataitem, fields, qd.begndate);

	 fields = L"enddate";
	 assigncstring2json(dataitem, fields, qd.enddate);

	 fields = L"med_list_codg";
	 assigncstring2json(dataitem, fields, qd.med_list_codg);

	 fields = L"mdtrt_id";
	 assigncstring2json(dataitem, fields, qd.mdtrt_id);
 
	 fields = L"psn_no";
	 assigncstring2json(dataitem, fields, qd.psn_no);

	 fields = L"psn_cert_type";
	 assigncstring2json(dataitem, fields, qd.psn_cert_type);

	 fields = L"certno";
	 assigncstring2json(dataitem, fields, qd.certno);

	 fields = L"psn_name";
	 assigncstring2json(dataitem, fields, qd.psn_name);

	 fields = L"drug_trac_codg";
     assigncstring2json(dataitem, fields, qd.drug_trac_codg);

	 inputitem[L"data"] = dataitem;


	 gs.returncode = 0;

	 int result = buildrequestjson(infno, msgid, gs.insuplc_admdvs,
		 gs.mdtrtarea_admvs, gs.opter_type, gs.opter, gs.opter_name, gs.inf_time,
		 gs.fixmedins_code, gs.fixmedins_name, gs.sign_no,
		 inputitem, obj, gs.returncode);

	 if (result != 0)
	 {
		 gs.returncode = result;
		 return gs.returncode;
	 }



	 wstring webaddress=L"http://10.33.56.12/myquery";
	 
	 
	  

	 json::value jv;

	 string accessKeystr = gs.accessKey;
	 string secreKeystr = gs.secreKey;
	 json::value outputwstr;

	 int mymethod = 0;
	 std::string txtfile;

	 result = postoweb(webaddress, obj, jv,
		 accessKeystr, secreKeystr, grs.inf_refmsgid, grs.refmsg_time,
		 grs.respond_time, grs.err_msg, outputwstr, gs.returncode, mymethod, txtfile, true);

	 if (result != 0)
	 {
		 gs.returncode = result;
		 return gs.returncode;
	 }

	 try
	 {


		 json::value retjv = outputwstr;

		 if (retjv.has_field(L"output"))
		 {
			 if (!retjv.at(L"output").is_null())
			 {
				 json::value setldetailjson = retjv.at(L"output");

				 json::array setldetailarray = setldetailjson.as_array();

				 recordscount = 0;

				 for (auto const & e : setldetailarray)
				 {
					 wstring field = L"fixmedinsCode";
					 obtaincstringfromjson2(e, field, tcr[recordscount].fixmedinsCode);

					 field = L"medListCodg";
					 obtaincstringfromjson2(e, field, tcr[recordscount].medListCodg);

					 field = L"medinsListCodg";
					 obtaincstringfromjson2(e, field, tcr[recordscount].medinsListCodg);

					 field = L"medinsListName";
					 obtaincstringfromjson2(e, field, tcr[recordscount].medinsListName);

					 field = L"fixmedinsBchno";
					 obtaincstringfromjson2(e, field, tcr[recordscount].fixmedinsBchno);

					 field = L"mdtrtId";
					 obtaincstringfromjson2(e, field, tcr[recordscount].mdtrtId);

					 field = L"mdtrtSetlType";
					 obtaincstringfromjson2(e, field, tcr[recordscount].mdtrtSetlType);

					 field = L"bkkpSn";
					 obtaincstringfromjson2(e, field, tcr[recordscount].bkkpSn);

					 field = L"drugTracCodg";
					 obtaincstringfromjson2(e, field, tcr[recordscount].drugTracCodg);

					 field = L"psnNo";
					 obtaincstringfromjson2(e, field, tcr[recordscount].psnNo);

					 field = L"psnCertType";
					 obtaincstringfromjson2(e, field, tcr[recordscount].psnCertType);

					 field = L"certno";
					 obtaincstringfromjson2(e, field, tcr[recordscount].certno);

					 field = L"psnName";
					 obtaincstringfromjson2(e, field, tcr[recordscount].psnName);

					 field = L"memo";
					 obtaincstringfromjson2(e, field, tcr[recordscount].memo);

					 field = L"trdnFlag";
					 obtaincstringfromjson2(e, field, tcr[recordscount].trdnFlag);

					 field = L"updtTime";
					 obtaincstringfromjson2(e, field, tcr[recordscount].updtTime);

					 field = L"opterName";
					 obtaincstringfromjson2(e, field, tcr[recordscount].opterName);

					 field = L"rid";
					 obtaincstringfromjson2(e, field, tcr[recordscount].rid);

					 field = L"crteTime";
					 obtaincstringfromjson2(e, field, tcr[recordscount].crteTime);

					 field = L"optTime";
					 obtaincstringfromjson2(e, field, tcr[recordscount].optTime);

					 field = L"opterId";
					 obtaincstringfromjson2(e, field, tcr[recordscount].opterId);

					 field = L"crterName";
					 obtaincstringfromjson2(e, field, tcr[recordscount].crterName);

					 field = L"crterId";
					 obtaincstringfromjson2(e, field, tcr[recordscount].crterId);

					 field = L"optinsNo";
					 obtaincstringfromjson2(e, field, tcr[recordscount].optinsNo);

					 recordscount++;
				 }


			 }
		 }
	 }
	 catch (const std::exception& e)
	 {
		 write_text_to_log_file(e.what());
		 return -999;
	 }


	 return 0;
 }

 

I have tracked the code, it has done for return 0

it encountred some problems afterward as some pics on attachments

any helps would be appreciated, actually I am kinda considering using Powerbuilder native Jsons as well as http features for doing this. but if you have suggestions for me for this problem I would be even more appreciated 

 

Attachments (2)

Who is viewing this page
Responses (1)
  1. Likes
  2. Latest
  3. Oldest
Loading...

Find Questions by Tag

.EXE .NET 6.0 .NET Assembly .NET Core 3.1 .NET Core Framework .NET DataStore .NET Std Framework 32-bit 64-bit ADO.NET AEM AI Algorithm Amazon AWS Android Apache API APK App Store App Store (Apple) Appeon Workspace Appeon Xcelerator Plug-in Architecture Array ASE Asynchronous Methods Authentication AutoBuild AutoCompiler Automated Testing Automation AutoScript Azure Barcode Base64 Batch BigData BLOB Branch & Merge Browser Bug Build Button C# C# Class Importer C# Editor C# Model generator Calendar Camera Certificate Chrome Citrix Class Client Client/Server Cloud Cluster Collection COM Command Line Compiler Compression Computed Field Configuration Controls Cookies Cordova Crash Cross-Platform Crosstab CSharpAssembly CSharpObject CSS CSV Cursor Data Database Database Driver Database Painter Database Profile Database Provider DataObject DataSource DataStore DataStore (C#) DataStore (PS) DataType DataWindow DATE DATETIME DB2 Debug Debugger Debugging Deployment Design DLL DO-WHILE Dockable Docker Documentation DOUBLE Download DragDrop Edge Edit Style Editor Elevate Conference Email Embedded SQL Emulator Encoding Encryption Enhancement Request Entity Entity Framework ERP Error Event Event Handler Event Handling Excel Exception Export Expression External Functions F# Field File File Access Filter Firefox Firewall Font FOR-NEXT Foreground Format Function Garbage Collection GeoLocation Git Graph HANA Hash Header HTML/5 HTTP/S HTTPClient Icon IDE Identity IIS IMAPI Import InfoMaker Inheritance Installation Integer IntelliSense Interface Internet Internet Explorer iOS IPA iPad iPhone IWA J# Java JavaScript JBoss JDBC JOIN JSON JSONGenerator JSONParser Kestrel Label Lambda Large File LDAP Library License LINQ Linux OS Load Balancing Localization Localized PBVM Log In Log Out Logging LONG LONGLONG macOS MAPI Maps MDI Memory Memory Leak Menu Merge MessageBox Messagging Method Migration MIME TYPE Mobile Model ModelStore ModelStore (C#) MSOLEDBSQL Multi Threading MVC MySQL n-Tier Namespace NativePDF NVO OAuth ODATA ODBC Office Offline OLE OLEDB Online Open Source OpenAPI OpenSSL Oracle OrcaScript Other Outlook Output Package Parameter Patch PayPal PB Classic PB Native PB.NET PBC PBD PBDOM PBG PBJVM PBL PBNI PBORCA PBVM PBX PDF Performance Permission PFC Picture Pipeline Play Store (Google) Plugin Popup Port POST PostgreSQL PowerBuilder PowerBuilder (Appeon) PowerBuilder (SAP) PowerBuilder Compiler PowerBuilder Runtime PowerClient PowerScript (PS) PowerScript IDE PowerScript Migrator PowerServer PowerServer Mobile PowerServer Toolkit PowerServer Web PowerServerLabel Print Properties Proxy Publish PULL PUSH Query Regression Release Renew Resize Response REST Retrieve RibbonBar RibbonBar Builder Rich Text Roadmap RPC Runtime Packager SaaS Scaffolding Script SDI SDK Security Server Service Session Single Sign-on Size SMTP SMTPClient SnapDevelop SOAP Sort Source Code Speech Recognition SQL SQL Anywhere SQL Server SqlBuilder SqlExecutor SQLite SqlModelMapper Storage Stored Procedure Subscription SVN Swagger Syntax TabbedBar TabbedView Tablet TabPage Target TE Control Testing Text TFS Theme TIME Timer TLS/SSL Tomcat TortoiseGit TortoiseSVN Transaction Transparency Trial Trigger TRY-CATCH TX Control Type UI ULONG UltraLite Uninstall Unit Test Unit Testing UNIX OS Update Upgrade Upload URL User Center User Object UWP Validation VARCHAR Variable Versioning Visual Studio Visual Studio Code VM Voice Warning WCF Web API Web Extensions Web Service WebBrowser WebForms WebLogic WebSphere WildFly WinAPI Window Windows OS WinForms Wizard Workgroup Workspace WPF XCODE XHTML XML Zoom

Helpful?

If a reply or comment is helpful for you, please don’t hesitate to click the Helpful button. This action is further confirmation of their invaluable contribution to the Appeon Community.