ABAP Select data from SAP table /PM0/ABD_CM_POLPR 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/ABD_CM_POLPR 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/ABD_CM_POLPR. 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/ABD_CM_POLPR 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/ABD_CM_POLPR TYPE STANDARD TABLE OF /PM0/ABD_CM_POLPR, WA_/PM0/ABD_CM_POLPR TYPE /PM0/ABD_CM_POLPR, 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/ABD_CM_POLPR> TYPE /PM0/ABD_CM_POLPR. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_/PM0/ABD_CM_POLPR. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM /PM0/ABD_CM_POLPR INTO TABLE IT_/PM0/ABD_CM_POLPR. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM /PM0/ABD_CM_POLPR * INTO TABLE @DATA(IT_/PM0/ABD_CM_POLPR2). *--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/ABD_CM_POLPR INDEX 1 INTO DATA(WA_/PM0/ABD_CM_POLPR2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_/PM0/ABD_CM_POLPR ASSIGNING </PM0/ABD_CM_POLPR>.*To update a field value using a field symbol simply change the value via the field symbol pointer
</PM0/ABD_CM_POLPR>-PPDPAC_ID = 1.
</PM0/ABD_CM_POLPR>-POLICYPRODUCT_ID = 1.
</PM0/ABD_CM_POLPR>-APPLNR_TT = 1.
</PM0/ABD_CM_POLPR>-APPLNROLD_TT = 1.
</PM0/ABD_CM_POLPR>-NUMOFCOV_AM = 1.
ENDLOOP. LOOP AT IT_/PM0/ABD_CM_POLPR INTO WA_/PM0/ABD_CM_POLPR. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_/PM0/ABD_CM_POLPR-LOB_CD, sy-vline,
WA_/PM0/ABD_CM_POLPR-POLPRODBEG_DT, sy-vline,
WA_/PM0/ABD_CM_POLPR-POLPRODEND_DT, sy-vline,
WA_/PM0/ABD_CM_POLPR-COMMENT_ID, sy-vline,
WA_/PM0/ABD_CM_POLPR-COMPANYKEY_CD, sy-vline,
WA_/PM0/ABD_CM_POLPR-STARTTIME_TM, sy-vline.
ENDLOOP. *Add any further fields from structure WA_/PM0/ABD_CM_POLPR 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/ABD_CM_POLPR 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/ABD_CM_POLPR INTO WA_/PM0/ABD_CM_POLPR. *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 APPLNR_TT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_/PM0/ABD_CM_POLPR-APPLNR_TT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/PM0/ABD_CM_POLPR-APPLNR_TT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field APPLNROLD_TT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_/PM0/ABD_CM_POLPR-APPLNROLD_TT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/PM0/ABD_CM_POLPR-APPLNROLD_TT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field INSOBJECT_ID CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_/PM0/ABD_CM_POLPR-INSOBJECT_ID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/PM0/ABD_CM_POLPR-INSOBJECT_ID.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field PROVAPPLNR_TT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_/PM0/ABD_CM_POLPR-PROVAPPLNR_TT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/PM0/ABD_CM_POLPR-PROVAPPLNR_TT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field ACCUMULATNR_TT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_/PM0/ABD_CM_POLPR-ACCUMULATNR_TT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/PM0/ABD_CM_POLPR-ACCUMULATNR_TT.
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/ABD_CM_POLPR_STR,
PPDPAC_ID TYPE STRING,
POLICYPRODUCT_ID TYPE STRING,
APPLNR_TT TYPE STRING,
APPLNROLD_TT TYPE STRING,
NUMOFCOV_AM TYPE STRING,
LOB_CD TYPE STRING,
POLPRODBEG_DT TYPE STRING,
POLPRODEND_DT TYPE STRING,
COMMENT_ID TYPE STRING,
COMPANYKEY_CD TYPE STRING,
STARTTIME_TM TYPE STRING,
STARTTIMEZONE_TT TYPE STRING,
ENDTIME_TM TYPE STRING,
ENDTIMEZONE_TT TYPE STRING,
IFBR_ID TYPE STRING,
BOSTAT_CD TYPE STRING,
POLPRC_CD TYPE STRING,
ACTINACTST_CD TYPE STRING,
EXTENS_FG TYPE STRING,
MAXDISBBOOKED_ID TYPE STRING,
MAXCOLLBOOKED_ID TYPE STRING,
CANCREAS_CD TYPE STRING,
CCLDATE_DT TYPE STRING,
REVERSAL_TM TYPE STRING,
REVTIMEZONE_TT TYPE STRING,
ACCVAR_CD TYPE STRING,
LSTATUS_CD TYPE STRING,
ICC_CD TYPE STRING,
ICCTRANS_DT TYPE STRING,
ICCEND_DT TYPE STRING,
ICCEND_TM TYPE STRING,
ICCTIMEZONE_TT TYPE STRING,
ICCDUNOT_CD TYPE STRING,
SUSPTP_CD TYPE STRING,
SUSPBEG_DT TYPE STRING,
SUSPBEG_TM TYPE STRING,
SUSPBEGTIMEZ_TT TYPE STRING,
SUSPEND_DT TYPE STRING,
SUSPEND_TM TYPE STRING,
SUSPENDTIMEZ_TT TYPE STRING,
TECHSTART_DT TYPE STRING,
MAXCARDINAL_VL TYPE STRING,
EXTVARIA_CD TYPE STRING,
CPSPOS_FG TYPE STRING,
DYNAMIC_FG TYPE STRING,
TARGRPB_CD TYPE STRING,
MANTAR_FG TYPE STRING,
GENERATION_DT TYPE STRING,
PRT_CD TYPE STRING,
PM_ID TYPE STRING,
TECHISA2P_FG TYPE STRING,
LEGALISA2P_FG TYPE STRING,
AGEATEXPIRAT_VL TYPE STRING,
CLEARDATE_DT TYPE STRING,
ACCEPTREJECT_DT TYPE STRING,
REFUSALREASON_CD TYPE STRING,
ORIGSTATE_TS TYPE STRING,
INSOBJECT_ID TYPE STRING,
COMMISPEND_FG TYPE STRING,
COMMISPOSTTX_CD TYPE STRING,
WHOLELIFE_FG TYPE STRING,
PROVAPPLNR_TT TYPE STRING,
COUNTRY_CD TYPE STRING,
TAXPAYERINFO_CD TYPE STRING,
ACCUMULATNR_TT TYPE STRING,
/PM0/ABDAPOLPR_CID TYPE STRING,
ACCVAR_TT TYPE STRING,
ACTINACTST_TT TYPE STRING,
APPL_DT TYPE STRING,
BASICD_TT TYPE STRING,
BINDEREXP_DT TYPE STRING,
BINDER_AM TYPE STRING,
CANCREAS_TT TYPE STRING,
COMMISPOSTTX_TT TYPE STRING,
COMPANYKEY_TT TYPE STRING,
CORKEY_TT TYPE STRING,
DATE1_DT TYPE STRING,
DISCLCORR_FG TYPE STRING,
DISCLSHOW_FG TYPE STRING,
DUPL_FG TYPE STRING,
IFBR_TT TYPE STRING,
INCREASEVAR_TT TYPE STRING,
INFLRIDPM_ID TYPE STRING,
INFLRIDPM_TT TYPE STRING,
INFRDTP_TT TYPE STRING,
INFRD_TP TYPE STRING,
INFRIDERTYPE_TT TYPE STRING,
INSDURINYEARS_AM TYPE STRING,
INSDURREMD_AM TYPE STRING,
INSDURREMM_AM TYPE STRING,
NOTE_FG TYPE STRING,
OVERDUENOTVAR_AM TYPE STRING,
PBSTYP_TT TYPE STRING,
POLPRC_TT TYPE STRING,
PREMPM_ID TYPE STRING,
PREMPM_TT TYPE STRING,
PROCESSSTATUS_FG TYPE STRING,
PRODUCT_TT TYPE STRING,
PRT_TT TYPE STRING,
REFUSALREASON_TT TYPE STRING,
SUSPTP_TT TYPE STRING,
TARGETDATE_DT TYPE STRING,
TARGRPB_TT TYPE STRING,
TAXPAYER_TT TYPE STRING,
TECHSTARTTIME_TM TYPE STRING,
TSTARTTMZONE_TT TYPE STRING,
COUNTRY_TT TYPE STRING,
ORGPOLPRODEXP_DT TYPE STRING,
REGION_CD TYPE STRING,
REGION_TT TYPE STRING,
TAXEXEMPT_CD TYPE STRING,END OF T_EKKO_STR. DATA: WA_/PM0/ABD_CM_POLPR_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/ABD_CM_POLPR_STR-PPDPAC_ID sy-vline
WA_/PM0/ABD_CM_POLPR_STR-POLICYPRODUCT_ID sy-vline
WA_/PM0/ABD_CM_POLPR_STR-APPLNR_TT sy-vline
WA_/PM0/ABD_CM_POLPR_STR-APPLNROLD_TT sy-vline
WA_/PM0/ABD_CM_POLPR_STR-NUMOFCOV_AM sy-vline
WA_/PM0/ABD_CM_POLPR_STR-LOB_CD sy-vline
WA_/PM0/ABD_CM_POLPR_STR-POLPRODBEG_DT sy-vline
WA_/PM0/ABD_CM_POLPR_STR-POLPRODEND_DT sy-vline
WA_/PM0/ABD_CM_POLPR_STR-COMMENT_ID sy-vline
WA_/PM0/ABD_CM_POLPR_STR-COMPANYKEY_CD sy-vline
WA_/PM0/ABD_CM_POLPR_STR-STARTTIME_TM sy-vline
WA_/PM0/ABD_CM_POLPR_STR-STARTTIMEZONE_TT sy-vline
WA_/PM0/ABD_CM_POLPR_STR-ENDTIME_TM sy-vline
WA_/PM0/ABD_CM_POLPR_STR-ENDTIMEZONE_TT sy-vline
WA_/PM0/ABD_CM_POLPR_STR-IFBR_ID sy-vline
WA_/PM0/ABD_CM_POLPR_STR-BOSTAT_CD sy-vline
WA_/PM0/ABD_CM_POLPR_STR-POLPRC_CD sy-vline
WA_/PM0/ABD_CM_POLPR_STR-ACTINACTST_CD sy-vline
WA_/PM0/ABD_CM_POLPR_STR-EXTENS_FG sy-vline
WA_/PM0/ABD_CM_POLPR_STR-MAXDISBBOOKED_ID sy-vline
WA_/PM0/ABD_CM_POLPR_STR-MAXCOLLBOOKED_ID sy-vline
WA_/PM0/ABD_CM_POLPR_STR-CANCREAS_CD sy-vline
WA_/PM0/ABD_CM_POLPR_STR-CCLDATE_DT sy-vline
WA_/PM0/ABD_CM_POLPR_STR-REVERSAL_TM sy-vline
WA_/PM0/ABD_CM_POLPR_STR-REVTIMEZONE_TT sy-vline
WA_/PM0/ABD_CM_POLPR_STR-ACCVAR_CD sy-vline
WA_/PM0/ABD_CM_POLPR_STR-LSTATUS_CD sy-vline
WA_/PM0/ABD_CM_POLPR_STR-ICC_CD sy-vline
WA_/PM0/ABD_CM_POLPR_STR-ICCTRANS_DT sy-vline
WA_/PM0/ABD_CM_POLPR_STR-ICCEND_DT sy-vline
WA_/PM0/ABD_CM_POLPR_STR-ICCEND_TM sy-vline
WA_/PM0/ABD_CM_POLPR_STR-ICCTIMEZONE_TT sy-vline
WA_/PM0/ABD_CM_POLPR_STR-ICCDUNOT_CD sy-vline
WA_/PM0/ABD_CM_POLPR_STR-SUSPTP_CD sy-vline
WA_/PM0/ABD_CM_POLPR_STR-SUSPBEG_DT sy-vline
WA_/PM0/ABD_CM_POLPR_STR-SUSPBEG_TM sy-vline
WA_/PM0/ABD_CM_POLPR_STR-SUSPBEGTIMEZ_TT sy-vline
WA_/PM0/ABD_CM_POLPR_STR-SUSPEND_DT sy-vline
WA_/PM0/ABD_CM_POLPR_STR-SUSPEND_TM sy-vline
WA_/PM0/ABD_CM_POLPR_STR-SUSPENDTIMEZ_TT sy-vline
WA_/PM0/ABD_CM_POLPR_STR-TECHSTART_DT sy-vline
WA_/PM0/ABD_CM_POLPR_STR-MAXCARDINAL_VL sy-vline
WA_/PM0/ABD_CM_POLPR_STR-EXTVARIA_CD sy-vline
WA_/PM0/ABD_CM_POLPR_STR-CPSPOS_FG sy-vline
WA_/PM0/ABD_CM_POLPR_STR-DYNAMIC_FG sy-vline
WA_/PM0/ABD_CM_POLPR_STR-TARGRPB_CD sy-vline
WA_/PM0/ABD_CM_POLPR_STR-MANTAR_FG sy-vline
WA_/PM0/ABD_CM_POLPR_STR-GENERATION_DT sy-vline
WA_/PM0/ABD_CM_POLPR_STR-PRT_CD sy-vline
WA_/PM0/ABD_CM_POLPR_STR-PM_ID sy-vline
WA_/PM0/ABD_CM_POLPR_STR-TECHISA2P_FG sy-vline
WA_/PM0/ABD_CM_POLPR_STR-LEGALISA2P_FG sy-vline
WA_/PM0/ABD_CM_POLPR_STR-AGEATEXPIRAT_VL sy-vline
WA_/PM0/ABD_CM_POLPR_STR-CLEARDATE_DT sy-vline
WA_/PM0/ABD_CM_POLPR_STR-ACCEPTREJECT_DT sy-vline
WA_/PM0/ABD_CM_POLPR_STR-REFUSALREASON_CD sy-vline
WA_/PM0/ABD_CM_POLPR_STR-ORIGSTATE_TS sy-vline
WA_/PM0/ABD_CM_POLPR_STR-INSOBJECT_ID sy-vline
WA_/PM0/ABD_CM_POLPR_STR-COMMISPEND_FG sy-vline
WA_/PM0/ABD_CM_POLPR_STR-COMMISPOSTTX_CD sy-vline
WA_/PM0/ABD_CM_POLPR_STR-WHOLELIFE_FG sy-vline
WA_/PM0/ABD_CM_POLPR_STR-PROVAPPLNR_TT sy-vline
WA_/PM0/ABD_CM_POLPR_STR-COUNTRY_CD sy-vline
WA_/PM0/ABD_CM_POLPR_STR-TAXPAYERINFO_CD sy-vline
WA_/PM0/ABD_CM_POLPR_STR-ACCUMULATNR_TT sy-vline
WA_/PM0/ABD_CM_POLPR_STR-/PM0/ABDAPOLPR_CID sy-vline
WA_/PM0/ABD_CM_POLPR_STR-ACCVAR_TT sy-vline
WA_/PM0/ABD_CM_POLPR_STR-ACTINACTST_TT sy-vline
WA_/PM0/ABD_CM_POLPR_STR-APPL_DT sy-vline
WA_/PM0/ABD_CM_POLPR_STR-BASICD_TT sy-vline
WA_/PM0/ABD_CM_POLPR_STR-BINDEREXP_DT sy-vline
WA_/PM0/ABD_CM_POLPR_STR-BINDER_AM sy-vline
WA_/PM0/ABD_CM_POLPR_STR-CANCREAS_TT sy-vline
WA_/PM0/ABD_CM_POLPR_STR-COMMISPOSTTX_TT sy-vline
WA_/PM0/ABD_CM_POLPR_STR-COMPANYKEY_TT sy-vline
WA_/PM0/ABD_CM_POLPR_STR-CORKEY_TT sy-vline
WA_/PM0/ABD_CM_POLPR_STR-DATE1_DT sy-vline
WA_/PM0/ABD_CM_POLPR_STR-DISCLCORR_FG sy-vline
WA_/PM0/ABD_CM_POLPR_STR-DISCLSHOW_FG sy-vline
WA_/PM0/ABD_CM_POLPR_STR-DUPL_FG sy-vline
WA_/PM0/ABD_CM_POLPR_STR-IFBR_TT sy-vline
WA_/PM0/ABD_CM_POLPR_STR-INCREASEVAR_TT sy-vline
WA_/PM0/ABD_CM_POLPR_STR-INFLRIDPM_ID sy-vline
WA_/PM0/ABD_CM_POLPR_STR-INFLRIDPM_TT sy-vline
WA_/PM0/ABD_CM_POLPR_STR-INFRDTP_TT sy-vline
WA_/PM0/ABD_CM_POLPR_STR-INFRD_TP sy-vline
WA_/PM0/ABD_CM_POLPR_STR-INFRIDERTYPE_TT sy-vline
WA_/PM0/ABD_CM_POLPR_STR-INSDURINYEARS_AM sy-vline
WA_/PM0/ABD_CM_POLPR_STR-INSDURREMD_AM sy-vline
WA_/PM0/ABD_CM_POLPR_STR-INSDURREMM_AM sy-vline
WA_/PM0/ABD_CM_POLPR_STR-NOTE_FG sy-vline
WA_/PM0/ABD_CM_POLPR_STR-OVERDUENOTVAR_AM sy-vline
WA_/PM0/ABD_CM_POLPR_STR-PBSTYP_TT sy-vline
WA_/PM0/ABD_CM_POLPR_STR-POLPRC_TT sy-vline
WA_/PM0/ABD_CM_POLPR_STR-PREMPM_ID sy-vline
WA_/PM0/ABD_CM_POLPR_STR-PREMPM_TT sy-vline
WA_/PM0/ABD_CM_POLPR_STR-PROCESSSTATUS_FG sy-vline
WA_/PM0/ABD_CM_POLPR_STR-PRODUCT_TT sy-vline
WA_/PM0/ABD_CM_POLPR_STR-PRT_TT sy-vline
WA_/PM0/ABD_CM_POLPR_STR-REFUSALREASON_TT sy-vline
WA_/PM0/ABD_CM_POLPR_STR-SUSPTP_TT sy-vline
WA_/PM0/ABD_CM_POLPR_STR-TARGETDATE_DT sy-vline
WA_/PM0/ABD_CM_POLPR_STR-TARGRPB_TT sy-vline
WA_/PM0/ABD_CM_POLPR_STR-TAXPAYER_TT sy-vline
WA_/PM0/ABD_CM_POLPR_STR-TECHSTARTTIME_TM sy-vline
WA_/PM0/ABD_CM_POLPR_STR-TSTARTTMZONE_TT sy-vline
WA_/PM0/ABD_CM_POLPR_STR-COUNTRY_TT sy-vline
WA_/PM0/ABD_CM_POLPR_STR-ORGPOLPRODEXP_DT sy-vline
WA_/PM0/ABD_CM_POLPR_STR-REGION_CD sy-vline
WA_/PM0/ABD_CM_POLPR_STR-REGION_TT sy-vline
WA_/PM0/ABD_CM_POLPR_STR-TAXEXEMPT_CD sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.