ABAP Select data from SAP table /PM0/ABT_BI_PREM into internal table

Get Example source ABAP code based on a different SAP table
  

Below is a number of ABAP code snippets to demonstrate how to select data from SAP /PM0/ABT_BI_PREM table and store it within an internal table, including using the newer @DATA inline declaration methods. It also shows you various ways to process this data using ABAP work area, inline declaration or field symbols including executing all the relevant CONVERSION_EXIT routines specific to /PM0/ABT_BI_PREM. See here for more generic Select statement tips.

Sometimes data within SAP is stored within the database table in a different format to what it is displayed to the user. These input/output conversation FM routines are what translates the data between the two formats.

There is also a full declaration of the /PM0/ABT_BI_PREM table where each field has a char/string type for you to simply copy and paste. This allows you to use processing that is only available to these field types such as the CONCATENATE statement.

DATA: IT_/PM0/ABT_BI_PREM TYPE STANDARD TABLE OF /PM0/ABT_BI_PREM,
      WA_/PM0/ABT_BI_PREM TYPE /PM0/ABT_BI_PREM,
      GD_STR TYPE STRING.

DATA: lo_typedescr type REF TO cl_abap_typedescr.
DATA: lv_fieldname type fieldname.

FIELD-SYMBOLS: <FIELD> TYPE any.
FIELD-SYMBOLS: </PM0/ABT_BI_PREM> TYPE /PM0/ABT_BI_PREM.

*Process all fields in table header/work area as string values
  PERFORM process_as_string_field_values CHANGING wa_/PM0/ABT_BI_PREM.

SELECT *
*restrict ABAP select to first 10 rows
 UP TO 10 ROWS      
  FROM /PM0/ABT_BI_PREM
  INTO TABLE IT_/PM0/ABT_BI_PREM.

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM /PM0/ABT_BI_PREM
*  INTO TABLE @DATA(IT_/PM0/ABT_BI_PREM2).
*--Further methods of using ABAP code to  select data from SAP database tables

*You can also declare the header/work area using the in-line DATA declaration method
READ TABLE IT_/PM0/ABT_BI_PREM INDEX 1 INTO DATA(WA_/PM0/ABT_BI_PREM2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_/PM0/ABT_BI_PREM ASSIGNING </PM0/ABT_BI_PREM>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
</PM0/ABT_BI_PREM>-POLICY_ID = 1.
</PM0/ABT_BI_PREM>-PPDPAC_ID = 1.
</PM0/ABT_BI_PREM>-POLICYPRODUCT_ID = 1.
</PM0/ABT_BI_PREM>-COVPAC_ID = 1.
</PM0/ABT_BI_PREM>-COVERAGE_ID = 1.
ENDLOOP.

LOOP AT IT_/PM0/ABT_BI_PREM INTO WA_/PM0/ABT_BI_PREM.
*Write horizonal line to screen report.
  WRITE:/ sy-uline.

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_/PM0/ABT_BI_PREM-COVCP_ID, sy-vline,
WA_/PM0/ABT_BI_PREM-SUBJECT_ID, sy-vline,
WA_/PM0/ABT_BI_PREM-PREMIUM_ID, sy-vline,
WA_/PM0/ABT_BI_PREM-CLIENT, sy-vline,
WA_/PM0/ABT_BI_PREM-MOD_TS, sy-vline,
WA_/PM0/ABT_BI_PREM-VALID_FROM_DT, sy-vline.
ENDLOOP. *Add any further fields from structure WA_/PM0/ABT_BI_PREM you want to display... WRITE:/ sy-uline. * Aternatively use generic code to Write field values (and NAME) to screen report DO. ASSIGN COMPONENT sy-index OF STRUCTURE wa_/PM0/ABT_BI_PREM TO <field>. IF sy-subrc <> 0. EXIT. ENDIF. WRITE:/ 'Field Value', <field>, sy-vline. gd_str = <field> . lo_typedescr ?= CL_ABAP_DATADESCR=>DESCRIBE_BY_DATA( <field> ). lv_fieldname = lo_typedescr->GET_RELATIVE_NAME( ). WRITE:/ 'Field Name', lv_fieldname. ENDDO. *Redo loop but convert all fields from internal to out value LOOP AT IT_/PM0/ABT_BI_PREM INTO WA_/PM0/ABT_BI_PREM. *Write horizonal line to screen report. WRITE:/ sy-uline. *Convert all fields to display/output versions using conversion routines PERFORM convert_all_field_values CHANGING wa_EKKO. ENDLOOP. *&---------------------------------------------------------------------* *& Form convert_all_field_values *&---------------------------------------------------------------------* FORM convert_all_field_values CHANGING p_EKKO LIKE wa_EKKO. DATA: ld_input(1000) TYPE c, ld_output(1000) TYPE C.

*Conversion exit ALPHA, internal->external for field SYSTEM_ID CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_/PM0/ABT_BI_PREM-SYSTEM_ID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/PM0/ABT_BI_PREM-SYSTEM_ID.
WRITE:/ 'New Value:', ld_input.

*Conversion exit J7NUM, internal->external for field PAYFRQ_CD CALL FUNCTION 'CONVERSION_EXIT_J7NUM_OUTPUT' EXPORTING input = WA_/PM0/ABT_BI_PREM-PAYFRQ_CD IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/PM0/ABT_BI_PREM-PAYFRQ_CD.
WRITE:/ 'New Value:', ld_input.

*Conversion exit J7PHD, internal->external for field PREMENDB_DT CALL FUNCTION 'CONVERSION_EXIT_J7PHD_OUTPUT' EXPORTING input = WA_/PM0/ABT_BI_PREM-PREMENDB_DT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/PM0/ABT_BI_PREM-PREMENDB_DT.
WRITE:/ 'New Value:', ld_input.

*Conversion exit J7AMD, internal->external for field MAINMATURITY_DT CALL FUNCTION 'CONVERSION_EXIT_J7AMD_OUTPUT' EXPORTING input = WA_/PM0/ABT_BI_PREM-MAINMATURITY_DT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/PM0/ABT_BI_PREM-MAINMATURITY_DT.
WRITE:/ 'New Value:', ld_input.

*Conversion exit J7NUM, internal->external for field PREMRATE_UT CALL FUNCTION 'CONVERSION_EXIT_J7NUM_OUTPUT' EXPORTING input = WA_/PM0/ABT_BI_PREM-PREMRATE_UT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/PM0/ABT_BI_PREM-PREMRATE_UT.
WRITE:/ 'New Value:', ld_input.
ENDFORM. *&---------------------------------------------------------------------* *& Form process_as_string_field_values *&---------------------------------------------------------------------* FORM process_as_string_field_values CHANGING p_EKKO LIKE wa_EKKO. TYPES: BEGIN OF T_/PM0/ABT_BI_PREM_STR,
POLICY_ID TYPE STRING,
PPDPAC_ID TYPE STRING,
POLICYPRODUCT_ID TYPE STRING,
COVPAC_ID TYPE STRING,
COVERAGE_ID TYPE STRING,
COVCP_ID TYPE STRING,
SUBJECT_ID TYPE STRING,
PREMIUM_ID TYPE STRING,
CLIENT TYPE STRING,
MOD_TS TYPE STRING,
VALID_FROM_DT TYPE STRING,
ORDERNO_ID TYPE STRING,
BALEFFECTIVE_DT TYPE STRING,
CANCEFFECTIVE_DT TYPE STRING,
SYSTEM_ID TYPE STRING,
JOURNALNO_ID TYPE STRING,
DEL_FG TYPE STRING,
DELTA_FG TYPE STRING,
PMDELTAMODE_FG TYPE STRING,
PMBIRUN_ID TYPE STRING,
BO_CD TYPE STRING,
LOBJOURNALNO_ID TYPE STRING,
RELEASED_DT TYPE STRING,
PM_ID TYPE STRING,
CORRECTED_AM TYPE STRING,
LOB_CD TYPE STRING,
PAYFRQ_CD TYPE STRING,
PREMBEFORETAX_AM TYPE STRING,
PREMAFTERTAX_AM TYPE STRING,
PREM_CD TYPE STRING,
CALCPREMB_AM TYPE STRING,
CALCPREMSUMB_AM TYPE STRING,
CLEAROFSURPLB_AM TYPE STRING,
CLEAROFSUPLPB_AM TYPE STRING,
GROSSPREMIUMB_AM TYPE STRING,
GROSSPREMIMPB_AM TYPE STRING,
INSAMTDISCB_AM TYPE STRING,
PAIDPREMIUMB_AM TYPE STRING,
PREMBEGB_DT TYPE STRING,
PREMDISCB_AM TYPE STRING,
PREMENDB_DT TYPE STRING,
PREMTRUNCCORB_AM TYPE STRING,
RATESUPPB_AM TYPE STRING,
RISKSUPPMEDB_AM TYPE STRING,
RISKSUPPVARB_AM TYPE STRING,
SAFETYSUPPLB_AM TYPE STRING,
UNITCOSTB_AM TYPE STRING,
MAINMATURITY_DT TYPE STRING,
PRMXMPT_FG TYPE STRING,
PRMXMPTEND_DT TYPE STRING,
NETPREMMAN_AM TYPE STRING,
PREMRATE_VL TYPE STRING,
CURRENCY_ID TYPE STRING,
PREMRATE_UT TYPE STRING,
MANTAR_FG TYPE STRING,
TARPREM_AM TYPE STRING,
ANNPREMAFTTAX_AM TYPE STRING,
ANNPREMBEFTAX_AM TYPE STRING,
ANNUALPREMB_VL TYPE STRING,
ANNUALNETPREM_AM TYPE STRING,
CUMTAXDEDUCT_AM TYPE STRING,
AGEATEXPIRATB_VL TYPE STRING,
FIRSTPREM_AM TYPE STRING,
ANNUALPREMIUM_AM TYPE STRING,
DIFCLEAROFSUR_AM TYPE STRING,
DIFGROSSPREM_AM TYPE STRING,
PAYMETHOD_CD TYPE STRING,
PREMTAXABLE_AM TYPE STRING,
SUPDCYTOT_AM TYPE STRING,
TOTALDISCOUNT_AM TYPE STRING,
INTIMPREMRATE_VL TYPE STRING,
INTIMANNPREM_AM TYPE STRING,
PRODUCTMAPP_ID TYPE STRING,
COLLTYPE_CD TYPE STRING,
PRMXMPTENDSPE_CD TYPE STRING,
RISKSUPPANN_AM TYPE STRING,
PAYFRQBEG_DT TYPE STRING,
CUSTOMER_PB_CI TYPE STRING,
/MVA/EXRATADD_FG TYPE STRING,
/MVA/CLAIMSZ_AM TYPE STRING,
/MVA/CLAIM_ID TYPE STRING,
/MVA/CLAIMS_AM TYPE STRING,
NETPREMWOLUS_AM TYPE STRING,
COPAYMENT_AM TYPE STRING,
RESPREM_AM TYPE STRING,
PREMDEP_FG TYPE STRING,
WOLUSANNEPRE_AM TYPE STRING,
CURR_ID TYPE STRING,
ALLOCKEY_CD TYPE STRING,
NETINVESTMENT_AM TYPE STRING,
INVESTMENT_CD TYPE STRING,
STATUSINDICAT_FG TYPE STRING,
PAYMPREM_AM TYPE STRING,
PROCESSPREM_FG TYPE STRING,
PREMSTATUS_CD TYPE STRING,
INVPREM_AM TYPE STRING,
REIMPLPRIM_ID TYPE STRING,
ARROFPREM_AM TYPE STRING,
CRTINVCF_FG TYPE STRING,
ADDEPCALCRULE_VL TYPE STRING,
CUSTOMER_PL_CI TYPE STRING,END OF T_EKKO_STR. DATA: WA_/PM0/ABT_BI_PREM_STR type T_EKKO_STR. DATA: ld_text TYPE string. LOOP AT IT_EKKO INTO WA_EKKO. MOVE-CORRESPONDING wa_EKKO TO WA_EKKO_STR. CONCATENATE: sy-vline
WA_/PM0/ABT_BI_PREM_STR-POLICY_ID sy-vline
WA_/PM0/ABT_BI_PREM_STR-PPDPAC_ID sy-vline
WA_/PM0/ABT_BI_PREM_STR-POLICYPRODUCT_ID sy-vline
WA_/PM0/ABT_BI_PREM_STR-COVPAC_ID sy-vline
WA_/PM0/ABT_BI_PREM_STR-COVERAGE_ID sy-vline
WA_/PM0/ABT_BI_PREM_STR-COVCP_ID sy-vline
WA_/PM0/ABT_BI_PREM_STR-SUBJECT_ID sy-vline
WA_/PM0/ABT_BI_PREM_STR-PREMIUM_ID sy-vline
WA_/PM0/ABT_BI_PREM_STR-CLIENT sy-vline
WA_/PM0/ABT_BI_PREM_STR-MOD_TS sy-vline
WA_/PM0/ABT_BI_PREM_STR-VALID_FROM_DT sy-vline
WA_/PM0/ABT_BI_PREM_STR-ORDERNO_ID sy-vline
WA_/PM0/ABT_BI_PREM_STR-BALEFFECTIVE_DT sy-vline
WA_/PM0/ABT_BI_PREM_STR-CANCEFFECTIVE_DT sy-vline
WA_/PM0/ABT_BI_PREM_STR-SYSTEM_ID sy-vline
WA_/PM0/ABT_BI_PREM_STR-JOURNALNO_ID sy-vline
WA_/PM0/ABT_BI_PREM_STR-DEL_FG sy-vline
WA_/PM0/ABT_BI_PREM_STR-DELTA_FG sy-vline
WA_/PM0/ABT_BI_PREM_STR-PMDELTAMODE_FG sy-vline
WA_/PM0/ABT_BI_PREM_STR-PMBIRUN_ID sy-vline
WA_/PM0/ABT_BI_PREM_STR-BO_CD sy-vline
WA_/PM0/ABT_BI_PREM_STR-LOBJOURNALNO_ID sy-vline
WA_/PM0/ABT_BI_PREM_STR-RELEASED_DT sy-vline
WA_/PM0/ABT_BI_PREM_STR-PM_ID sy-vline
WA_/PM0/ABT_BI_PREM_STR-CORRECTED_AM sy-vline
WA_/PM0/ABT_BI_PREM_STR-LOB_CD sy-vline
WA_/PM0/ABT_BI_PREM_STR-PAYFRQ_CD sy-vline
WA_/PM0/ABT_BI_PREM_STR-PREMBEFORETAX_AM sy-vline
WA_/PM0/ABT_BI_PREM_STR-PREMAFTERTAX_AM sy-vline
WA_/PM0/ABT_BI_PREM_STR-PREM_CD sy-vline
WA_/PM0/ABT_BI_PREM_STR-CALCPREMB_AM sy-vline
WA_/PM0/ABT_BI_PREM_STR-CALCPREMSUMB_AM sy-vline
WA_/PM0/ABT_BI_PREM_STR-CLEAROFSURPLB_AM sy-vline
WA_/PM0/ABT_BI_PREM_STR-CLEAROFSUPLPB_AM sy-vline
WA_/PM0/ABT_BI_PREM_STR-GROSSPREMIUMB_AM sy-vline
WA_/PM0/ABT_BI_PREM_STR-GROSSPREMIMPB_AM sy-vline
WA_/PM0/ABT_BI_PREM_STR-INSAMTDISCB_AM sy-vline
WA_/PM0/ABT_BI_PREM_STR-PAIDPREMIUMB_AM sy-vline
WA_/PM0/ABT_BI_PREM_STR-PREMBEGB_DT sy-vline
WA_/PM0/ABT_BI_PREM_STR-PREMDISCB_AM sy-vline
WA_/PM0/ABT_BI_PREM_STR-PREMENDB_DT sy-vline
WA_/PM0/ABT_BI_PREM_STR-PREMTRUNCCORB_AM sy-vline
WA_/PM0/ABT_BI_PREM_STR-RATESUPPB_AM sy-vline
WA_/PM0/ABT_BI_PREM_STR-RISKSUPPMEDB_AM sy-vline
WA_/PM0/ABT_BI_PREM_STR-RISKSUPPVARB_AM sy-vline
WA_/PM0/ABT_BI_PREM_STR-SAFETYSUPPLB_AM sy-vline
WA_/PM0/ABT_BI_PREM_STR-UNITCOSTB_AM sy-vline
WA_/PM0/ABT_BI_PREM_STR-MAINMATURITY_DT sy-vline
WA_/PM0/ABT_BI_PREM_STR-PRMXMPT_FG sy-vline
WA_/PM0/ABT_BI_PREM_STR-PRMXMPTEND_DT sy-vline
WA_/PM0/ABT_BI_PREM_STR-NETPREMMAN_AM sy-vline
WA_/PM0/ABT_BI_PREM_STR-PREMRATE_VL sy-vline
WA_/PM0/ABT_BI_PREM_STR-CURRENCY_ID sy-vline
WA_/PM0/ABT_BI_PREM_STR-PREMRATE_UT sy-vline
WA_/PM0/ABT_BI_PREM_STR-MANTAR_FG sy-vline
WA_/PM0/ABT_BI_PREM_STR-TARPREM_AM sy-vline
WA_/PM0/ABT_BI_PREM_STR-ANNPREMAFTTAX_AM sy-vline
WA_/PM0/ABT_BI_PREM_STR-ANNPREMBEFTAX_AM sy-vline
WA_/PM0/ABT_BI_PREM_STR-ANNUALPREMB_VL sy-vline
WA_/PM0/ABT_BI_PREM_STR-ANNUALNETPREM_AM sy-vline
WA_/PM0/ABT_BI_PREM_STR-CUMTAXDEDUCT_AM sy-vline
WA_/PM0/ABT_BI_PREM_STR-AGEATEXPIRATB_VL sy-vline
WA_/PM0/ABT_BI_PREM_STR-FIRSTPREM_AM sy-vline
WA_/PM0/ABT_BI_PREM_STR-ANNUALPREMIUM_AM sy-vline
WA_/PM0/ABT_BI_PREM_STR-DIFCLEAROFSUR_AM sy-vline
WA_/PM0/ABT_BI_PREM_STR-DIFGROSSPREM_AM sy-vline
WA_/PM0/ABT_BI_PREM_STR-PAYMETHOD_CD sy-vline
WA_/PM0/ABT_BI_PREM_STR-PREMTAXABLE_AM sy-vline
WA_/PM0/ABT_BI_PREM_STR-SUPDCYTOT_AM sy-vline
WA_/PM0/ABT_BI_PREM_STR-TOTALDISCOUNT_AM sy-vline
WA_/PM0/ABT_BI_PREM_STR-INTIMPREMRATE_VL sy-vline
WA_/PM0/ABT_BI_PREM_STR-INTIMANNPREM_AM sy-vline
WA_/PM0/ABT_BI_PREM_STR-PRODUCTMAPP_ID sy-vline
WA_/PM0/ABT_BI_PREM_STR-COLLTYPE_CD sy-vline
WA_/PM0/ABT_BI_PREM_STR-PRMXMPTENDSPE_CD sy-vline
WA_/PM0/ABT_BI_PREM_STR-RISKSUPPANN_AM sy-vline
WA_/PM0/ABT_BI_PREM_STR-PAYFRQBEG_DT sy-vline
WA_/PM0/ABT_BI_PREM_STR-CUSTOMER_PB_CI sy-vline
WA_/PM0/ABT_BI_PREM_STR-/MVA/EXRATADD_FG sy-vline
WA_/PM0/ABT_BI_PREM_STR-/MVA/CLAIMSZ_AM sy-vline
WA_/PM0/ABT_BI_PREM_STR-/MVA/CLAIM_ID sy-vline
WA_/PM0/ABT_BI_PREM_STR-/MVA/CLAIMS_AM sy-vline
WA_/PM0/ABT_BI_PREM_STR-NETPREMWOLUS_AM sy-vline
WA_/PM0/ABT_BI_PREM_STR-COPAYMENT_AM sy-vline
WA_/PM0/ABT_BI_PREM_STR-RESPREM_AM sy-vline
WA_/PM0/ABT_BI_PREM_STR-PREMDEP_FG sy-vline
WA_/PM0/ABT_BI_PREM_STR-WOLUSANNEPRE_AM sy-vline
WA_/PM0/ABT_BI_PREM_STR-CURR_ID sy-vline
WA_/PM0/ABT_BI_PREM_STR-ALLOCKEY_CD sy-vline
WA_/PM0/ABT_BI_PREM_STR-NETINVESTMENT_AM sy-vline
WA_/PM0/ABT_BI_PREM_STR-INVESTMENT_CD sy-vline
WA_/PM0/ABT_BI_PREM_STR-STATUSINDICAT_FG sy-vline
WA_/PM0/ABT_BI_PREM_STR-PAYMPREM_AM sy-vline
WA_/PM0/ABT_BI_PREM_STR-PROCESSPREM_FG sy-vline
WA_/PM0/ABT_BI_PREM_STR-PREMSTATUS_CD sy-vline
WA_/PM0/ABT_BI_PREM_STR-INVPREM_AM sy-vline
WA_/PM0/ABT_BI_PREM_STR-REIMPLPRIM_ID sy-vline
WA_/PM0/ABT_BI_PREM_STR-ARROFPREM_AM sy-vline
WA_/PM0/ABT_BI_PREM_STR-CRTINVCF_FG sy-vline
WA_/PM0/ABT_BI_PREM_STR-ADDEPCALCRULE_VL sy-vline
WA_/PM0/ABT_BI_PREM_STR-CUSTOMER_PL_CI sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.