ABAP Select data from SAP table PIQAUD_PROPOSED_COURSES 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 PIQAUD_PROPOSED_COURSES 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 PIQAUD_PROPOSED_COURSES. 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 PIQAUD_PROPOSED_COURSES 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_PIQAUD_PROPOSED_COURSES TYPE STANDARD TABLE OF PIQAUD_PROPOSED_COURSES,
      WA_PIQAUD_PROPOSED_COURSES TYPE PIQAUD_PROPOSED_COURSES,
      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: <PIQAUD_PROPOSED_COURSES> TYPE PIQAUD_PROPOSED_COURSES.

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

SELECT *
*restrict ABAP select to first 10 rows
 UP TO 10 ROWS      
  FROM PIQAUD_PROPOSED_COURSES
  INTO TABLE IT_PIQAUD_PROPOSED_COURSES.

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM PIQAUD_PROPOSED_COURSES
*  INTO TABLE @DATA(IT_PIQAUD_PROPOSED_COURSES2).
*--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_PIQAUD_PROPOSED_COURSES INDEX 1 INTO DATA(WA_PIQAUD_PROPOSED_COURSES2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_PIQAUD_PROPOSED_COURSES ASSIGNING <PIQAUD_PROPOSED_COURSES>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<PIQAUD_PROPOSED_COURSES>-SEQNR = 1.
<PIQAUD_PROPOSED_COURSES>-SUBREQ_ID = 1.
<PIQAUD_PROPOSED_COURSES>-NODEID = 1.
<PIQAUD_PROPOSED_COURSES>-ACADEMICWORKID = 1.
<PIQAUD_PROPOSED_COURSES>-AGRID = 1.
ENDLOOP.

LOOP AT IT_PIQAUD_PROPOSED_COURSES INTO WA_PIQAUD_PROPOSED_COURSES.
*Write horizonal line to screen report.
  WRITE:/ sy-uline.

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_PIQAUD_PROPOSED_COURSES-AWOTYPE, sy-vline,
WA_PIQAUD_PROPOSED_COURSES-AWOBJID, sy-vline,
WA_PIQAUD_PROPOSED_COURSES-AWBEGDATE, sy-vline,
WA_PIQAUD_PROPOSED_COURSES-AWENDDATE, sy-vline,
WA_PIQAUD_PROPOSED_COURSES-AWLOCKFLAG, sy-vline,
WA_PIQAUD_PROPOSED_COURSES-AWSTATUS, sy-vline.
ENDLOOP. *Add any further fields from structure WA_PIQAUD_PROPOSED_COURSES 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_PIQAUD_PROPOSED_COURSES 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_PIQAUD_PROPOSED_COURSES INTO WA_PIQAUD_PROPOSED_COURSES. *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 CUNIT, internal->external for field CPUNIT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_PIQAUD_PROPOSED_COURSES-CPUNIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PIQAUD_PROPOSED_COURSES-CPUNIT.
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_PIQAUD_PROPOSED_COURSES_STR,
SEQNR TYPE STRING,
SUBREQ_ID TYPE STRING,
NODEID TYPE STRING,
ACADEMICWORKID TYPE STRING,
AGRID TYPE STRING,
AWOTYPE TYPE STRING,
AWOBJID TYPE STRING,
AWBEGDATE TYPE STRING,
AWENDDATE TYPE STRING,
AWLOCKFLAG TYPE STRING,
AWSTATUS TYPE STRING,
CANCELREASON TYPE STRING,
CANCELDATE TYPE STRING,
BOOKDATE TYPE STRING,
AWRATING TYPE STRING,
CHARGEFREE TYPE STRING,
TRANSFERFLAG TYPE STRING,
EVENTPACKAGE TYPE STRING,
ACAD_SESSION TYPE STRING,
ACAD_YEAR TYPE STRING,
BOOKREASON TYPE STRING,
ANNULMENT TYPE STRING,
COBOK TYPE STRING,
PRIOX TYPE STRING,
ALT_SCALEID TYPE STRING,
AGRTYPE TYPE STRING,
AGRSTAT TYPE STRING,
GRADESYMBOL TYPE STRING,
GRADE TYPE STRING,
GRADESCALE TYPE STRING,
AGRNOTRATED TYPE STRING,
AGRDATE TYPE STRING,
AGRCOMPLETED TYPE STRING,
CPATTEMP TYPE STRING,
CPEARNED TYPE STRING,
CPGRADED TYPE STRING,
CPUNIT TYPE STRING,
AGRREMARK TYPE STRING,
AGRBEGDA TYPE STRING,
AGRENDDA TYPE STRING,
ARCH_STATUS TYPE STRING,
NOTEID TYPE STRING,
GRADECHANGED TYPE STRING,
PUBLICATIONDATE TYPE STRING,
AWTEXT TYPE STRING,
ATTNO_TW TYPE STRING,
AWOTYPE_TXT TYPE STRING,
AWOBJECT_SHT TYPE STRING,
AWOBJECT_TXT TYPE STRING,
AWSTATUS_TXT TYPE STRING,
CANCELREASON_TXT TYPE STRING,
AWRATING_TXT TYPE STRING,
EVENTPACKAGE_SHT TYPE STRING,
EVENTPACKAGE_TXT TYPE STRING,
ACAD_SESSION_TXT TYPE STRING,
ACAD_YEAR_TXT TYPE STRING,
BOOKREASON_TXT TYPE STRING,
ANNULMENT_TXT TYPE STRING,
AGRTYPE_TXT TYPE STRING,
AGRSTAT_TXT TYPE STRING,
GRADESYMBOL_TXT TYPE STRING,
GRADESCALE_TXT TYPE STRING,
CPUNIT_TXT TYPE STRING,
AGRREMARK_TXT TYPE STRING,
COBOK_TXT TYPE STRING,
TIMES_USED TYPE STRING,
NOT_BOOKED TYPE STRING,
UPDATEFLAG TYPE STRING,
WEIGHTING TYPE STRING,
SUBSTITUTION_FLAG TYPE STRING,END OF T_EKKO_STR. DATA: WA_PIQAUD_PROPOSED_COURSES_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_PIQAUD_PROPOSED_COURSES_STR-SEQNR sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-SUBREQ_ID sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-NODEID sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-ACADEMICWORKID sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-AGRID sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-AWOTYPE sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-AWOBJID sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-AWBEGDATE sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-AWENDDATE sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-AWLOCKFLAG sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-AWSTATUS sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-CANCELREASON sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-CANCELDATE sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-BOOKDATE sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-AWRATING sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-CHARGEFREE sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-TRANSFERFLAG sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-EVENTPACKAGE sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-ACAD_SESSION sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-ACAD_YEAR sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-BOOKREASON sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-ANNULMENT sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-COBOK sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-PRIOX sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-ALT_SCALEID sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-AGRTYPE sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-AGRSTAT sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-GRADESYMBOL sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-GRADE sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-GRADESCALE sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-AGRNOTRATED sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-AGRDATE sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-AGRCOMPLETED sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-CPATTEMP sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-CPEARNED sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-CPGRADED sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-CPUNIT sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-AGRREMARK sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-AGRBEGDA sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-AGRENDDA sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-ARCH_STATUS sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-NOTEID sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-GRADECHANGED sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-PUBLICATIONDATE sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-AWTEXT sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-ATTNO_TW sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-AWOTYPE_TXT sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-AWOBJECT_SHT sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-AWOBJECT_TXT sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-AWSTATUS_TXT sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-CANCELREASON_TXT sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-AWRATING_TXT sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-EVENTPACKAGE_SHT sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-EVENTPACKAGE_TXT sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-ACAD_SESSION_TXT sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-ACAD_YEAR_TXT sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-BOOKREASON_TXT sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-ANNULMENT_TXT sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-AGRTYPE_TXT sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-AGRSTAT_TXT sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-GRADESYMBOL_TXT sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-GRADESCALE_TXT sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-CPUNIT_TXT sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-AGRREMARK_TXT sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-COBOK_TXT sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-TIMES_USED sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-NOT_BOOKED sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-UPDATEFLAG sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-WEIGHTING sy-vline
WA_PIQAUD_PROPOSED_COURSES_STR-SUBSTITUTION_FLAG sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.