..3 Printing program

Here is the nugget to install objects via SAPLINK .

Create a report Z_GANTTCHART and paste below code into it:


REPORT z_ganttchart .


* declare the context

DATA gs_context TYPE zcontext_ganttchart .


* fill the context

PERFORM fill_context .


* call the form

CALL FUNCTION 'ZXLWB_CALLFORM'

EXPORTING

iv_formname = 'GANTTCHART'

iv_context_ref = gs_context

EXCEPTIONS

process_terminated = 1

OTHERS = 2.

IF sy-subrc NE 0 .

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 .

ENDIF .


*&---------------------------------------------------------------------*

*& Form fill_context

*&---------------------------------------------------------------------*

FORM fill_context .

TYPE-POOLS:

abap .

DATA:

lv_month TYPE i ,

lv_week TYPE char1 ,

lv_day TYPE numc2 ,

lv_day_c TYPE char1 ,

lv_day_text TYPE rnpb2-day_txt ,

lv_days TYPE i ,

lv_date TYPE dats ,

ls_par TYPE t009b ,

lv_index TYPE syindex .

FIELD-SYMBOLS:

<week> TYPE zcontext_ganttchart_week_s ,

<head_day> TYPE zcontext_ganttchart_head_day_s ,

<task_day> TYPE zcontext_ganttchart_task_day_s ,

<task> TYPE zcontext_ganttchart_task_s ,

<phase> TYPE zcontext_ganttchart_phase_s .


* get random month

CALL FUNCTION 'BKK_RANDOM'

EXPORTING

i_modulo = 12

IMPORTING

e_random_number = lv_month.


* determine number days of the month

ls_par-bumon = lv_month .

ls_par-bdatj = sy-datum(4) .


CALL FUNCTION 'NUMBER_OF_DAYS_PER_MONTH_GET'

EXPORTING

par_month = ls_par-bumon

par_year = ls_par-bdatj

IMPORTING

par_days = ls_par-butag.


lv_days = ls_par-butag .


* determine name of the month

SELECT SINGLE ltx

INTO gs_context-header-month_text

FROM t247

WHERE spras EQ sy-langu

AND mnr EQ lv_month .


CONCATENATE gs_context-header-month_text sy-datum(4)

INTO gs_context-header-month_text SEPARATED BY space .


*======================================================================

* header

*======================================================================

DO lv_days TIMES .

lv_day = sy-index .

CONCATENATE ls_par-bdatj ls_par-bumon lv_day INTO lv_date .


CALL FUNCTION 'ISH_GET_DAY_OF_WEEK'

EXPORTING

date = lv_date

IMPORTING

day = lv_day_c

day_txt = lv_day_text.


IF lv_day_c EQ 1

OR gs_context-header-weeks[] IS INITIAL .

APPEND INITIAL LINE TO gs_context-header-weeks

ASSIGNING <week> .

ADD 1 TO lv_week .

CONCATENATE 'Week' lv_week

INTO <week>-week_text SEPARATED BY space .

ENDIF .


APPEND INITIAL LINE TO <week>-days

ASSIGNING <head_day> .

<head_day>-day_text = lv_day_text .

<head_day>-day_number = lv_day .

ENDDO .


*======================================================================

* positions

*======================================================================

DO 9 TIMES .

lv_index = sy-index .


* new phase

CASE lv_index .

WHEN 1 .

APPEND INITIAL LINE TO gs_context-phases ASSIGNING <phase> .

<phase>-phase_text = 'Conceptuel design' .

WHEN 4 .

APPEND INITIAL LINE TO gs_context-phases ASSIGNING <phase> .

<phase>-phase_text = 'Prototype' .

WHEN 7 .

APPEND INITIAL LINE TO gs_context-phases ASSIGNING <phase> .

<phase>-phase_text = 'Testing' .

ENDCASE .


* new task

APPEND INITIAL LINE TO <phase>-tasks ASSIGNING <task> .

CASE lv_index .

WHEN 1 . <task>-task_name = 'Brainstorming' .

WHEN 2 . <task>-task_name = 'Gathering information' .

WHEN 3 . <task>-task_name = 'Concept selection' .

WHEN 4 . <task>-task_name = 'Programming' .

WHEN 5 . <task>-task_name = 'Assemble & testing' .

WHEN 6 . <task>-task_name = 'Final prototype' .

WHEN 7 . <task>-task_name = 'User testing' .

WHEN 8 . <task>-task_name = 'Modify & beta test' .

WHEN 9 . <task>-task_name = 'Quality assurance' .

ENDCASE .


* days

DO lv_days TIMES .

lv_day = sy-index .

APPEND INITIAL LINE TO <task>-days ASSIGNING <task_day> .

<task_day>-filled = abap_off .

<task_day>-empty = abap_on .


CASE lv_index .

WHEN 1 . CHECK lv_day EQ 1 .

WHEN 2 . CHECK lv_day BETWEEN 2 AND 3 .

WHEN 3 . CHECK lv_day EQ 4 .

WHEN 4 . CHECK lv_day BETWEEN 5 AND 16 .

WHEN 5 . CHECK lv_day BETWEEN 17 AND 19 .

WHEN 6 . CHECK lv_day BETWEEN 20 AND 22 .

WHEN 7 . CHECK lv_day BETWEEN 23 AND 24 .

WHEN 8 . CHECK lv_day BETWEEN 25 AND 27 .

WHEN OTHERS . CHECK lv_day GE 28 .

ENDCASE .


ADD 1 TO <task>-duration . CONDENSE <task>-duration NO-GAPS .

<task_day>-filled = abap_on .

<task_day>-empty = abap_off .

ENDDO .


ENDDO .


ENDFORM . "fill_context

Result of the printing program execution: