Author Topic: Liquid UI: Convert function module structure detail to type object  (Read 5585 times)

Leo Chu

  • GuiXT Forum
  • Newbie
  • *
  • Posts: 16
    • View Profile
Liquid UI: Convert function module structure detail to type object

This example is to convert function module structure detail to a type object, which is required when Use call command to get native SAP function module detail.

For each function module structure, it needs specific type object for call command to reference.

Quote
   var z_STRUCTURE_NAME = {
      name:STRUCTURE_NAME,
      components:[
         { name:COMPONENT_NAME,   length:DATA_LENGTH,   decimalpl:DECIMAL_POINT_LENGTH,   type:DATA_TYPE },
         ...
      ]
   };

In type object, each component has different ABAP data type, which can be referenced from below table.

LUI Type    ABAP Type     Data Type           Description                                                                                                                   
b'b'INT1Cannot be substituted with 'C'
C'C'CHAR, UNIT, LANG, CUKY, LCHR
D'D'DATSCan be substituted with 'C'
When used as 'D', the Component will be a JavaScript Date object,
whereas, if specified as 'C', it will be a string returned by SAP in the format of "19941107"
F or f'F'FLTPCannot be substituted with 'C'
For BAPI FM, specify LUI type as "F"; for FM RFC_READ_TABLE, specify LUI type as "f"
T'T'TIMSCurrently same as 'C' and can be substituted with 'C'
N'N'NUMCCan be substituted with 'C'
P or f'P'QUAN, DEC, CURRCannot be substituted with 'C'
For BAPI FM, specify LUI type as "P"; for FM RFC_READ_TABLE, specify LUI type as "f"
s or i's'INT2Cannot be substituted with 'C'
For BAPI FM, specify LUI type as "s"; for FM RFC_READ_TABLE, specify LUI type as "i"
I'I'INT, INT4Cannot be substituted with 'C'


Step 1: Check output structure according to parameter

The structure of each output parameter needs to be specified individually.
Its detail can be referenced from SAP in transaction SE37 follow by below steps.
1.   On initial screen of SE37, enter the FM
2.   Click on "Display" button to check detail
3.   On the display screen, select "Export" or "Tables" tab according to your output
4.   In corresponding tab, find the row of output parameter and double click on it to see detail structure
5.   Stay in the structure detail screen, and prepare to create the script based on the screen

Use FM BAPI_ALM_ORDER_GET_DETAIL as an example, its ES_HEADER parameter has structure BAPI_ALM_ORDER_HEADER_E which SAP screen should shown as below.

Component                               Typing Method     Component Type                          Data Type     Length     Decimal Pl     Short Description                                 
ORDERID1AUFNRCHAR120Order Number
ORDER_TYPE1AUFARTCHAR40Order Type
PLANPLANT1IWERKCHAR40Maintenance Planning Plant
BUS_AREA1GSBERCHAR40Business Area
MN_WK_CTR1GEWRKCHAR80Main work center for maintenance tasks
PLANT1WERGWCHAR40Plant associated with main work center
MN_WKCTR_ID1LGWIDNUMC80Object ID of the Work Center
PMACTTYPE1ILACHAR30Maintenance activity type
PLANGROUP1INGRPCHAR30Planner Group for Customer Service and Plant Maintenance
SYSTCOND1ANLZUCHAR10Syst.Condition
FUNCT_LOC1TPLNRCHAR300Functional Location
EQUIPMENT1EQUNRCHAR180Equipment Number
SERIALNO1GERNRCHAR180Serial Number
MATERIAL1MATNRCHAR180Material Number
ASSEMBLY1BAUTLCHAR180Assembly
DEVICEDATA1DEVICEIDCHAR400Additional Device Data
MAINTPLANT1SWERKCHAR40Maintenance plant
LOCATION1STORTCHAR100Asset location
MAINTROOM1RAUMNRCHAR80Room
PLSECTN1BEBERCHAR30Plant section
LOC_WK_CTR1ARBPLCHAR80Work center
LOC_WKCTR_ID1PPSIDNUMC80Object ID of PP work center
ABCINDIC1ABCKZCHAR10ABC indicator for technical object
SORTFIELD1EQFNRCHAR300Sort field
COMP_CODE1BUKRSCHAR40Company Code
PROFIT_CTR1PRCTRCHAR100Profit Center
CO_AREA1KOKRSCHAR40Controlling Area
RESPCCTR1AUFKOSTVCHAR100Responsible cost center
FUNC_AREA1FKBERCHAR160Functional Area
SUPERIOR_NETWORK1CO_TEILNETCHAR120Number of superior network
SUPERIOR_ACTIVITY1CN_VORNRCHAR40Activity number in network and standard network
SUPERIOR_ROUTING_NO1CO_AUFPLNUMC100Routing number of operations in the order
SUPERIOR_COUNTER1CO_APLZLNUMC80General counter for order
WBS_ELEM1PS_PSP_PNRNUMC80Work Breakdown Structure Element (WBS Element)
PROJ_DEF1PS_PSP_PRONUMC80Project definition
PROCESSING_GROUP1AUFABKRSNUMC20Processing group
OBJECTCLASS1SCOPE_CVCHAR20Object Class
TAXJURCODE1TXJCDCHAR150Tax Jurisdiction
LOC_COMP_CODE1BUKRSCHAR40Company Code
LOC_CO_AREA1KOKRSCHAR40Controlling Area
ASSET_NO1ANLN1CHAR120Main Asset Number
SUB_NUMBER1ANLN2CHAR40Asset Subnumber
LOC_BUS_AREA1GSBERCHAR40Business Area
COSTCENTER1KOSTLCHAR100Cost Center
LOC_WBS_ELEM1PS_PSP_PNRNUMC80Work Breakdown Structure Element (WBS Element)
STANDORDER1DAUFNCHAR120Standing order number
SETTLORDER1ILOM_ORDSTCHAR120Settlement order
SALESORG1VKORGCHAR40Sales Organization
DISTR_CHAN1VTWEGCHAR20Distribution Channel
DIVISION1SPARTCHAR20Division
ORDPLANID1AUF_PLKNZCHAR10Maintenance order planning indicator
START_DATE1CO_GSTRPDATS80Basic start date
FINISH_DATE1CO_GLTRPDATS80Basic finish date
BASICSTART1CO_GSUZPTIMS60Basic start time
BASIC_FIN1CO_GLUZPTIMS60Basic finish (time)
PRIORITY1PRIOKCHAR10Priority
REVISION1REVNICHAR80Revision for Plant Maintenance and Customer Service
VERSION1KAPVERSANUMC20Version of Available Capacity
SCHED_TYPE1TERMKZCHAR10Scheduling type
AUTOSCHED1CO_AUTERMCHAR10Indicator: Schedule automatically
CAP_REQMTS1AUKBEDCHAR10Indicator: Calculate capacity requirements
SCHEDULING_EXACT_BREAK_TIMES1BREAKSCHAR10Indicator:  Scheduling allowing for breaks
MRP_RELEVANT1AUDISP_PLUSCHAR10Reservation Relevance/Generation of Purchase Requisition
PRODUCTION_START_DATE1CO_GSTRSDATS80Scheduled start
PRODUCTION_FINISH_DATE1CO_GLTRSDATS80Scheduled finish
PRODUCTION_START_TIME1CO_GSUZSTIMS60Scheduled Start (Time)
PRODUCTION_FINISH_TIME1CO_GLUZSTIMS60Scheduled finish time
ACTUAL_START_DATE1CO_GSTRIDATS80Actual start date
ACTUAL_FINISH_DATE1CO_GETRIDATS80Confirmed Order Finish Date
ACTUAL_START_TIME1CO_GSUZITIMS60Actual start time
ACTUAL_FINISH_TIME1CO_GEUZITIMS60Confirmed order finish (time)
REFDATE1ADDATDATS80PM Order: Reference Date
SALES_ORD1KDAUFCHAR100Sales Order Number
S_ORD_ITEM1KDPOSNUMC60Item Number in Sales Order
CALC_MOTIVE1BEMOTCHAR20Accounting Indicator
INVEST_PROFILE1IM_PROFILCHAR60Investment measure profile
SCALE1IM_SIZECLCHAR20Scale of investment objects
INV_REASON1IZWEKCHAR20Reason for investment
ENVIR_INVEST1AM_UMWKZCHAR50Reason for environmental investment
ESTIMATED_COSTS1AUFUSER4CURR112Estimated total costs of order
CURRENCY1AUFWAERSCUKY50Order Currency
CURRENCY_ISO1ISOCDCHAR30ISO currency code
CSTG_SHEET1AUFKALSMCHAR60Costing Sheet
OVERHEAD_KEY1AUFZSCHLCHAR60Overhead key
RES_ANAL_KEY1ABGR_SCHLCHAR60Results Analysis Key
NETWORK_PROFILE1PROFIDNZPLCHAR70Network profile
CSTGVAPPLN1KALKVARPLNCHAR40Costing variant for planned costs
CSTGVARACT1KALKVARISTCHAR40Costing variant for actual costs
TASK_LIST_GROUP1PLNNRCHAR80Key for Task List Group
GROUP_COUNTER1PLNALCHAR20Group Counter
TASK_LIST_TYPE1PLNTYCHAR10Task List Type
RESP_PLANNER_GROUP1VAGRPCHAR30Responsible planner group/department
MNTPLAN1WARPLCHAR120Maintenance Plan
MAINTITEM1WAPOSCHAR160Maintenance item
CALL_NO1ABNUMINT4100Maintenance Plan Call Number
LAST_ORD1LAUFNCHAR120Order number
ENTERED_BY1AUFERFNAMCHAR120Entered by
ENTER_DATE1AUFERFDATDATS80Created on
CHANGED_BY1AUFAENAMCHAR120Last changed by
CHANGE_DATE1AUFAEDATDATS80Change date for Order Master
SCENARIO1SCRTPCHAR40Scenario or Subscreen Category
SYS_STATUS1CO_STTXTCHAR400System Status
USER_ST1CO_ASTEXCHAR10User status active
USERSTATUS1CO_ASTTXCHAR400Field displaying user status
STAT_PROF1J_STSMACHAR80Status Profile
OBJECT_NO1J_OBJNRCHAR220Object number
ROUTING_NO1CO_AUFPLNUMC100Routing number of operations in the order
RESERV_NO1RSNUMNUMC100Number of Reservation/Dependent Requirement
SHORT_TEXT1AUFTEXTCHAR400Description
LONG_TEXT1CO_LTEXTCHAR10Long text exists
NOTIF_NO1QMNUMCHAR120Notification No
ASSEMBLY_EXTERNAL1MGV_ASSEMBLY_EXTERNALCHAR400Long Material Number for Field ASSEMBLY
ASSEMBLY_GUID1MGV_ASSEMBLY_GUIDCHAR320External GUID for ASSEMBLY Field
ASSEMBLY_VERSION1MGV_ASSEMBLY_VERSIONCHAR100Version Number for ASSEMBLY Field
MATERIAL_EXTERNAL1MGV_MATERIAL_EXTERNALCHAR400Long Material Number for MATERIAL Field
MATERIAL_GUID1MGV_MATERIAL_GUIDCHAR320External GUID for MATERIAL Field
MATERIAL_VERSION1MGV_MATERIAL_VERSIONCHAR100Version Number for MATERIAL Field
CALID1WFCIDCHAR20Factory Calendar
KALSN1KALSNNUMC20Calendar Selection for Order
SUPERIOR_ORDERID1MAUFNRCHAR120Number of superior order
LEADING_ORDERID1CO_LAUFNRCHAR120Leading order in current processing
START_POINT1EAML_START_POINTCHAR180Start Point
END_POINT1EAML_END_POINTCHAR180End Point
LINEAR_LENGTH1EAML_LINEAR_LENGTHCHAR180Length
LINEAR_UNIT1EAML_LINEAR_UNITUNIT30Unit of Measurement for Linear Data
LINEAR_UNIT_ISO1EAML_LINEAR_UNIT_ISOCHAR30Unit of Measurement for Linear Data in ISO Code
FIRST_OFFSET_TYPE_CODE1EAML_OFFSET1_TYPE_CODECHAR20Type of First Offset
FIRST_OFFSET_VALUE1EAML_OFFSET1_VALUECHAR180Value of Offset 1
FIRST_OFFSET_UNIT1EAML_OFFSET1_UNITUNIT30Unit of Measurement for Offset 1
FIRST_OFFSET_UNIT_ISO1EAML_OFFSET1_UNIT_ISOCHAR30Unit of Measurement for Offset 1 in ISO Code
SECOND_OFFSET_TYPE_CODE1EAML_OFFSET2_TYPE_CODECHAR20Type of Second Offset
SECOND_OFFSET_VALUE1EAML_OFFSET2_VALUECHAR180Value of Offset 2
SECOND_OFFSET_UNIT1EAML_OFFSET2_UNITUNIT30Unit of Measurement for Offset 2
SECOND_OFFSET_UNIT_ISO1EAML_OFFSET2_UNIT_ISOCHAR30Unit of Measurement for Offset 2 in ISO Code
FIRST_OFFSET_TYPE_CODE_NAME1EAML_OFFSET1_TYPE_CODE_NAMECHAR600First Offset Type Description
SECOND_OFFSET_TYPE_CODE_NAME1EAML_OFFSET2_TYPE_CODE_NAMECHAR600Second Offset Type Description
MARKER_START_POINT1EAML_MARKER_START_POINTCHAR180Marker for Start Point
MARKER_DISTANCE_START_POINT1EAML_MARKER_DISTANCE_STARTCHAR180Distance between Marker and Start Point
MARKER_END_POINT1EAML_MARKER_END_POINTCHAR180Marker for End Point
MARKER_DISTANCE_END_POINT1EAML_MARKER_DISTANCE_ENDCHAR180Length Spec for Distance between Marker and End Point
MARKER_DISTANCE_UNIT1EAML_MARKER_DISTANCE_UNITUNIT30Unit for the Distance from Marker
MARKER_DISTANCE_UNIT_ISO1EAML_MARKER_DISTANCE_UNIT_ISOCHAR30Unit for the Distance from Marker in ISO Code
PRIOTYPE1ARTPRCHAR20Priority Type

Note:    Use "Ctrl+Y" can select table content from SAP GUI, then use "Ctrl+C" to copy



Step 2: Create lookup dictionary for different data type

According to different ABAP data types, we need to create a lookup dictionary when generating the structure object.

Quote
DATA_TYPE_REF_ARY = {
               "CHAR":"C", "UNIT":"C", "LANG":"C", "CUKY":"C", "LCHR":"C",
               "DATS":"D", "FLTP":"F", "TIMS":"T", "NUMC":"N",
               "QUAN":"P", "DEC":"P", "CURR":"P",
               "INT":"I", "INT1":"b", "INT2":"s", "INT4":"I"
   };

   

Step 3: Create custom layout on the screen

Quote
//Make sure this layout will only show in transaction SE37
if(_transaction == "SE37"){
   
   if(!z_se37_display_structure_obj){
      pushbutton([TOOLBAR], "Get Structure Object", "?", {"process":se37GetStructureObject});      //Trigger the function to generate structure object detail
   }
   else {
      pushbutton([TOOLBAR], "Clear Structure Object", "?", {"process":se37Reset});      //Trigger the function to reset all realted variables
     
      clearscreen();
     
      textbox([0,0], [30,200], {"name":"z_se37_structure_obj_text"});      //Textbox to display result structure object detail
   }
}   

   
   
Step 4: Create function to reset SE37 related variables   

Quote
function se37Reset(){
   set("V[z_se37*]", "");
}



Step 5: Create function to read the component table and return structure object detail   

Quote
function se37GetStructureObject(){
   
   onscreen "SAPLSD41.2100"
      set("V[z_se37_structure]", "&F[Structure]");            //Read the structure value
      var relrow = 1;
      var absrow = 1;
      var z_se37_component_ary = [];
      var z_se37_row_ary = [];
     
NEW_SCREEN:;     
      enter("/ScrollToLine=&V[absrow]", {"table":"T[SAPLSD41_TC0]"});
     
   onscreen "SAPLSD41.2100"
      gettableattribute("T[SAPLSD41_TC0]", {"firstvisiblerow":"FVisRow", "lastvisiblerow":"LVisRow", "lastrow":"LRow"});   
      relrow = 1;
NEW_ROW:;   
      if(absrow > LVisRow){
         goto NEW_SCREEN;
      }
   
      if(absrow > LRow){
         goto END_OF_TABLE;
      }
   
      z_se37_row_ary = [];
     
      //Read each row of component table
      set("V[cur_component]", "&cell[SAPLSD41_TC0,Component,&V[relrow]]");
      set("V[cur_typing_method]", "&cell[SAPLSD41_TC0,Typing Method,&V[relrow]]");
      set("V[cur_component_type]", "&cell[SAPLSD41_TC0,Component Type,&V[relrow]]");
      set("V[cur_data_type]", "&cell[SAPLSD41_TC0,Data Type,&V[relrow]]");
      set("V[cur_length]", "&cell[SAPLSD41_TC0,Length,&V[relrow]]");
      set("V[cur_decimal_pl]", "&cell[SAPLSD41_TC0,Decimal Pl,&V[relrow]]");
      set("V[cur_short_desc]", "&cell[SAPLSD41_TC0,Short Description,&V[relrow]]");
   
      z_se37_row_ary.push(cur_component);
      z_se37_row_ary.push(cur_typing_method);
      z_se37_row_ary.push(cur_component_type);
      z_se37_row_ary.push(cur_data_type);
      z_se37_row_ary.push(cur_length);
      z_se37_row_ary.push(cur_decimal_pl);
      z_se37_row_ary.push(cur_short_desc);
   
      z_se37_component_ary.push(z_se37_row_ary);
   
      relrow++;
      absrow++;
      goto NEW_ROW;
END_OF_TABLE:;

      //Change flag to display the result textbox
      z_se37_display_structure_obj = true;

      //Get organized structure object detail
      var z_se37_result_struct_ary = setStructureObject(z_se37_structure,z_se37_component_ary);      //Get organized result array from function
     
      //Logic to copy content from organized result array to longtext variable
      for(var struct in z_se37_result_struct_ary){         
         tmp_str = z_se37_result_struct_ary[struct];
         
         if(struct==0)
            copytext({"totext":"z_se37_structure_obj_text", "fromstring":"tmp_str"});
         else
            copytext({"totext":"z_se37_structure_obj_text", "fromstring":"tmp_str", "appendline":true});

      }
     
      enter("/ScrollToLine=1", {"table":"T[SAPLSD41_TC0]"});
}



Step 6: Create function to organized fetched table data   

Quote
function setStructureObject(structure,component_ary){
   var result_ary = [];
   var component_str = "";

   
   result_ary.push("\tvar z_" + structure + " = {\n");         //Decalre the type object
   result_ary.push("\t\tname:'" + structure + "',\n");         //Add the name variable
   result_ary.push("\t\tcomponents:[\n");                  //Add the components object
   
   for(var i=0; i<component_ary.length; i++){               //For loop to form each component
      component_str = "\t\t\t{ name:'" + component_ary[0] +
                  "', \tlength:" + component_ary[4] +
                  ",\tdecimalpl:" + component_ary[5] +
                  ",\ttype:'" + DATA_TYPE_REF_ARY[component_ary[3]] +
                  "' }" + ((i!=component_ary.length-1)?",\n":"\n") +
                  "\t" + ((component_ary[3]=="CHAR")?"\t\t\t\t":("/** " + component_ary[3] + " **/\t\t\t")) +
                  "//" + component_ary[6];
     
      result_ary.push(component_str);
   }
   
   result_ary.push("\t\t]\n");                           //End component object
   result_ary.push("\t};");                           //End type object
   
   return   result_ary;
}




Step 7: Copy result to your script   

After execution, the result of structure object should displayed in the textbox.
Now select everything from the textbox and copy to the targeting script.


   
See attachments for full script example 
« Last Edit: January 06, 2021, 01:40:01 PM by Leo Chu »